<?php

use yii\helpers\Html;
use yii\grid\GridView;
use app\models\Category;
use yii\helpers\ArrayHelper;
use dosamigos\datepicker\DatePicker;
/* @var $this yii\web\View */
/* @var $searchModel app\models\CategorySearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = 'Categories';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="category-index">

    <h1><?= Html::encode($this->title) ?></h1>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <p>
        <?= Html::a('Create Category', ['create'], ['class' => 'btn btn-success']) ?>
    </p>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            [
                'attribute'=>'name',
                'format'=>'raw',
                'value'=>function ($model){
                    return '<div>'.$model->name.'</div>';
                }
            ],
            [
                'attribute'=>'parent_id',
                'format'=>'raw',
                'value'=>function ($model){
                    return '<div>'.Category::getCategory($model->parent_id).'</div>';
                },
                'filter'=>ArrayHelper::map(Category::find()->all(),'id','name')
            ],
            [
                'attribute'=>'create_date',
                'format'=>'raw',
                'value'=>function ($model){
                    return '<div>'.$model->create_date.'</div>';
                }
            ],
            [
                'attribute'=>'update_date',
                'format'=>'raw',
                'value'=>function ($model){
                    return '<div>'.$model->update_date.'</div>';
                }
            ],
            [
                'attribute'=>'active',
                'format'=>'raw',
                'value'=>function ($model){
                    return '<div>'.$model->active.'</div>';
                }
            ],
            ['class' => 'yii\grid\ActionColumn'],
        ],
    ]); ?>

</div>
